var app = getApp()
var IP = app.globalData.IP
Page({
  data: {

    activeNames: ['1'],
    //定时器
    timer: {},
    //轮播图切换视频
    playvideo: false,

    show: false,
    serviceinfo: '',
    swiperimagelist: {},
    serviceid: '',

    controls: false,
    //服务保障弹出层
    visible1: false,

    //时间选择器
    datetimeVisible: false,
    datetime: new Date().getTime(),
    datetimeText: '',

    //接收地址数据
    address: '',

    //评论数组
    commentList: [],
  },
  onLoad(options) {
    this.setData({
      serviceid: options.serviceid
    })
    this.getServicebyServiceId()
    this.getServiceSwiperbyServiceId()
    this.QeuryCommentbyserviceid(this.data.serviceid)

  },
  onShow() {

  },

  navitomorecomment() {
    wx.navigateTo({
      url: '/pages/serviceDetail/commentList/commentList',
      success: res => {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('getcommentList', {
          commentList: this.data.commentList
        })

      }

    })


  },

  onclickRate(event) {
    this.setData({
      value: event.detail,
    });
  },
  QeuryCommentbyserviceid(serviceid) {
    wx.request({
      url: `http://${IP}:8080/Comment/QeuryCommentbyserviceid/` + serviceid,
      success: res => {
        console.log(res.data)
        this.setData({
          commentList: res.data
        })


      }
    })
  },

  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },


  // 时间选择器
  showPicker() {
    this.setData({
      datetimeVisible: true,
    });
  },
  hidePicker() {

    this.setData({
      datetimeVisible: false,
    });
  },
  onConfirm(e) {
    const {
      value
    } = e?.detail;

    this.setData({
      datetimeText: value,
    });

    this.hidePicker();
  },

  // 弹出层
  showPopup1() {
    this.setData({
      visible1: true
    }, );
  },

  onVisibleChange1(e) {
    this.setData({
      visible1: e.detail.visible,
    });
  },


  // 页面双向传数据
  naviTodDeliveryaddress() {
    if (wx.getStorageSync('islogin') == true) {
      wx.navigateTo({
        url: '/pages/usercenter/deliveryAddress/deliveryAddress',
        events: {
          // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
          acceptDataFromDeliveryAddress: data => {
            this.setData({
              address: data
            })

          },
        },
        success: function (res) {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('identity', {
            identity: "serviceDetail"
          })
        }

      })
    } else {
      wx.showModal({
        title: '',
        content: '请登录',
        showCancel: false
      });
      const timer = setTimeout(() => {
        wx.switchTab({
          url: '/pages/usercenter/index/index',
        })
      }, 1200)
      this.setData({
        timer: timer
      });

    }
  },

  naviToOrderSubmit() {
    if (wx.getStorageSync('islogin') == true) {
      wx.navigateTo({
        url: '/pages/order/ordersubmit/ordersubmit',
        events: {
          // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
        },
        success: res => {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('serviceDetailDataToOrderSubmit', {
            address: this.data.address,
            datetimeText: this.data.datetimeText,
            serviceinfo: this.data.serviceinfo
          })
        }

      })
    } else {
      wx.showModal({
        title: '',
        content: '请登录',
        showCancel: false
      });
      const timer = setTimeout(() => {
        wx.switchTab({
          url: '/pages/usercenter/index/index',
        })
      }, 1200)
      this.setData({
        timer: timer
      });

    }
  },


  //获取轮播图url
  getServiceSwiperbyServiceId() {
    wx.request({
      url: `http://${IP}:8080/service/getserviceswiperbyserviceid/` + this.data.serviceid,
      success: res => {
        this.setData({
          swiperimagelist: res.data
        })
      }
    })

  },
  //获取服务详细信息
  getServicebyServiceId() {
    wx.request({
      url: `http://${IP}:8080/service/getservicebyserviceid/` + this.data.serviceid,
      success: res => {
        this.setData({
          serviceinfo: res.data
        })
      }

    })

  },
  changetype() {
    this.setData({
      playvideo: true,
    })

  },
  // 暂停播放
  videoPause: function () {
    var videoplay = wx.createVideoContext("video");
    videoplay.pause()

  },






})